<script setup>
import { adminAddService, adminChangeStateService, adminDeleteService, adminEditService, adminListWithConditionService } from '@/api/admin'
import { userListWithConditionService } from '@/api/user'
import {
    Edit,
    Delete
} from '@element-plus/icons-vue'
import { ref } from 'vue'
import { Plus } from '@element-plus/icons-vue'
//导入token
import { userTokenStore } from '@/store/token'
const tokenStore = userTokenStore();
import '@vueup/vue-quill/dist/vue-quill.snow.css'
import { ElMessage, ElMessageBox } from 'element-plus'

//商品数据模型
const users = ref([
    {
        "userid": "ACID",
        "firstName": "A",
        "lastName": "B",
        "phone": "13344445555",
        "country": "China",
        "city": "cs",
        "email": "acid@yourdomain.com",
    },
    {
        "userid": "ACID",
        "firstName": "A",
        "lastName": "B",
        "phone": "13344445555",
        "country": "China",
        "city": "cs",
        "email": "acid@yourdomain.com",
    },
    {
        "userid": "ACID",
        "firstName": "A",
        "lastName": "B",
        "phone": "13344445555",
        "country": "China",
        "city": "cs",
        "email": "acid@yourdomain.com",
    },
])
//分页条数据模型
const pageNum = ref(1)//当前页
const total = ref(20)//总条数
const pageSize = ref(10)//每页条数

//用户搜索时输入的名字
const userIdForSearch = ref('')

//使用标题共用编辑框
const title = ref('');
//控制抽屉是否显示
const visibleDrawer = ref(false)

//当每页条数发生了变化，调用此函数
const onSizeChange = (size) => {
    pageSize.value = size;
    getUserWithCondition();
}
//当前页码发生变化，调用此函数
const onCurrentChange = (num) => {
    pageNum.value = num;
    getUserWithCondition();
}


//获取Item商品详情
const getUserWithCondition = async () => {
    //处理数据
    let params = {
        pageNum: pageNum.value,
        pageSize: pageSize.value,
        userId: userIdForSearch.value ? userIdForSearch.value : null,
    }
    let result = await userListWithConditionService(params);
    if (result) {
        total.value = result.data.total;
        users.value = result.data.list;
    }
}
getUserWithCondition();

//有条件搜索
const search = () => {
    getUserWithCondition();
    ElMessage('获取成功');
}
//无条件搜索,用于重置
const searchWithNoCondition = () => {
    userIdForSearch.value = null;
    getUserWithCondition();
    ElMessage('获取成功');
}


</script>

<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>用户管理</span>
            </div>
        </template>
        <!-- 搜索表单 -->
        <el-form inline>
            <el-form-item label="用户Id">
                <el-input v-model="userIdForSearch" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="search()">搜索</el-button>
                <el-button @click="searchWithNoCondition()">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- Item列表 -->
        <el-table :data="users" style="width: 100%">
            <el-table-column label="用户Id" prop="userid"></el-table-column>
            <el-table-column label="firstName" prop="firstName"></el-table-column>
            <el-table-column label="lastName" prop="lastName"> </el-table-column>
            <el-table-column label="电话" prop="phone"></el-table-column>
            <el-table-column label="所处国家" prop="country"></el-table-column>
            <el-table-column label="所处城市" prop="city"></el-table-column>
            <el-table-column label="邮箱" prop="email"></el-table-column>
            <template #empty>
                <el-empty description="没有数据" />
            </template>
        </el-table>
        <!-- 分页条 -->
        <el-pagination v-model:current-page="pageNum" v-model:page-size="pageSize" :page-sizes="[3, 5, 10, 15]"
            layout="jumper, total, sizes, prev, pager, next" background :total="total" @size-change="onSizeChange"
            @current-change="onCurrentChange" style="margin-top: 20px; justify-content: flex-end" />
    </el-card>
</template>
<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}

/* 抽屉样式 */
.avatar-uploader {
    :deep() {
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .el-upload {
            border: 1px dashed var(--el-border-color);
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
            transition: var(--el-transition-duration-fast);
        }

        .el-upload:hover {
            border-color: var(--el-color-primary);
        }

        .el-icon.avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            text-align: center;
        }
    }
}

.editor {
    width: 100%;

    :deep(.ql-editor) {
        min-height: 200px;
    }
}
</style>